<template>
	<view>
	{{code}}
	</view>
</template>

<script>
	import {
		initScan,
		startScan,
		stopScan
	} from "@/utils/scan";

	export default {
		data() {
			return {
				code:'',
			};
		},
		onShow() {
			initScan(this.scanSuccess);
			startScan();
		},
		onHide() {
			stopScan();
		},
		methods: {
			// 红外线扫码成功后
			async scanSuccess(code) {
				console.log('红外线扫码的结果', code);
				this.code = code;
				// 下面就是写取到结果后的事情
			}
		},
	}
</script>